package 单周赛.december;

import java.util.ArrayList;
import java.util.List;

/**
 * @link
 * @date 2023/12/10
 */
public class 第375场单周赛 {

    public static void main(String[] args) {


        System.out.println(countTestedDevices(new int[]{1, 1, 2, 1, 3}));

        System.out.println(fastPower(fastPower(6, 1, 10), 1, 4));

    }

    /**
     * 模拟
     */
    public static int countTestedDevices(int[] batteryPercentages) {
        int ans = 0;

        for (int i = 0; i < batteryPercentages.length; i++) {

            if (batteryPercentages[i] <= 0) {
                continue;
            }
            ans++;

            for (int j = i + 1; j < batteryPercentages.length; j++) {
                batteryPercentages[j]--;
            }

        }

        return ans;
    }

    /**
     * 快速幂
     * ((ai^bi % 10)^ci) % mi == target
     */
    public List<Integer> getGoodIndices(int[][] variables, int target) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < variables.length; i++) {
            int a = variables[i][0], b = variables[i][1], c = variables[i][2], m = variables[i][3];

            if (fastPower(fastPower(a, b, 10), c, m) == target) {
                list.add(i);
            }
        }

        return list;
    }

    // x 的 y 次幂对 mod 取模
    private static int fastPower(int x, int y, int mod) {
        if (y == 1) {
            return x % mod;
        }
        int ans = fastPower(x * x % mod, y / 2, mod);
        if (y % 2 == 1) {
            ans = ans * x % mod;
        }
        return ans;
    }

}
